<?php
$profileURL = Common::getBaseUrl().'user/profile/';
$addFriendURL = Common::getBaseUrl().'user/addfriend/';
$deleteFriendURL = Common::getBaseUrl().'user/deletefriend/';
$loggedIn = Auth::hasIdentity();
$loggedInUser = Auth::getIdentity();
$friends = DataHelper::getFriendList();
$friendList = array();
// put all friends in a list for checking
if (!empty($friends)) {
	foreach ($friends as $friend) {
		$friendList[] = $friend['account_friend_id'];
	}
}
?>
<section>
	<h2>List of Users Who Added Me</h2>
	<?php echo Common::renderFlashMessage() ?>
	<p><?php if($this->notifyMessage) { echo $this->notifyMessage; } ?></p>
	<p><?php if($this->errorMessage) { echo $this->errorMessage; } ?></p>
	<?php 
		if ($this->allFriends):
		foreach($this->allFriends as $friend): 
	?>
		<article class="friends">
			<div class="friendsUsername"><a href="<?php echo $profileURL.$friend['username']; ?>"><?php echo $friend['username']; ?></a></div>
			<?php 
				if ($loggedIn):
				if (in_array($friend['account_id'], $friendList)):
			?>
				<div class="friendsDelete"><a href="<?php echo $deleteFriendURL.$friend['username']; ?>">Delete</a></div>
			<?php else: ?>
				<div class="friendsAdd"><a href="<?php echo $addFriendURL.$friend['username']; ?>">Add</a></div>
			<?php 
				endif;
				endif; 
			?>
		</article>
	<?php	
		endforeach;
		endif;
	?>
</section>